Type.registerNamespace("Telerik.Web.UI");
Telerik.Web.UI.LayoutBuilderEngine=function(a){this._selectedTable=null;
this._selectedCell=null;
this._selectedRow=null;
this._selectedRowCells=[];
this._selectedRowIndex=null;
this._tableState=[];
this._tableStateRowsCount=0;
this._tableStateColsCount=0;
this._tableStateId="LayoutBuilder_tableState_dump";
this._tableStateTableStyle="radtblder_stateMatrixTable";
this._tableStateCellStyle="radtblder_stateMatrixCell";
this._selectedCellClassName="";
this._states=[];
this._currentStateIndex=-1;
this.set_selectedTable(a);
if(this._selectedTable){this.set_selectedCell();
}if(!a){a=document.createElement("TABLE");
}Telerik.Web.UI.LayoutBuilderEngine.initializeBase(this,[a]);
};
Telerik.Web.UI.LayoutBuilderEngine.prototype={get_selectedTable:function(){return this._selectedTable;
},set_selectedTable:function(a){this._selectedTable=null;
if(a&&a.tagName=="TABLE"){this._selectedTable=a;
this._setTableState();
}},get_selectedCell:function(){return this._selectedCell;
},set_selectedCell:function(c,b){if(!this._selectedTable||this._selectedTable.tagName!="TABLE"){return;
}if(!c){c=this._selectedTable.rows[0].cells[0];
}if(c.tagName=="TD"||c.tagName=="TH"){if(this._selectedCell!=c){this._selectedCellClassName=c.className;
}this._selectedCell=c;
}else{this._selectedCell=null;
}if(this._selectedCell){this.set_selectedRow();
}if(this._selectedCell&&(false!=b)&&this._currentStateIndex==-1){if(this._states.length==1&&this._states[0]["commandName"]=="selection"){this._states=[];
}var a={commandName:"selection",selectedColIndex:this._selectedCell.cellIndex,selectedRowIndex:this._selectedRowIndex,nextSelectedColIndex:this._selectedCell.cellIndex,nextSelectedRowIndex:this._selectedRowIndex};
this._storeState(a);
}},set_selectedRow:function(){if(this._selectedCell){this._selectedRow=this._selectedCell.parentNode;
if(this._selectedRow){this._selectedRowCells=this._selectedRow.cells;
this._selectedRowIndex=this._selectedRow.rowIndex;
}else{this._selectedRowCells=null;
this._selectedRowIndex=null;
}}},_raiseException:function(a){},_initializesTableStateCounts:function(){var d=this._selectedTable.rows;
var b=d.length;
var g=0;
for(var a=0;
a<b;
a++){var c=0;
var e=d[a].cells;
var h=e.length;
for(var f=0;
f<h;
f++){c+=this._getColSpan(e[f]);
}if(g<c){g=c;
}}this._tableStateRowsCount=b;
this._tableStateColsCount=g;
},dumpState:function(){var d=document.createElement("Table");
var a=$get(this._tableStateId);
if(a){a.parentNode.removeChild(a);
}d.id=this._tableStateId;
d.className=this._tableStateTableStyle;
var f=this._tableState.length;
for(i=0;
i<f;
i++){var b=this._tableState[i].length;
var e=d.insertRow(i);
for(j=0;
j<b;
j++){var c=e.insertCell(j);
c.className=this._tableStateCellStyle;
c.innerHTML=this._tableState[i][j];
}}this._selectedTable.parentNode.appendChild(d);
},_initializesTableState:function(d,a){for(var b=0;
b<d;
b++){this._tableState[b]=[];
for(var c=0;
c<a;
c++){this._tableState[b][c]="";
}}},_processTD:function(c,g,a){var d=this._getRowSpan(c);
var b=this._getColSpan(c);
for(var e=0;
e<d;
e++){for(var f=0;
f<b;
f++){this._tableState[g+e][a+f]=c.parentNode.rowIndex+","+c.cellIndex;
}}},_setTableState:function(){this._tableState=[];
this._initializesTableStateCounts();
this._initializesTableState(this._tableStateRowsCount,this._tableStateColsCount);
var f=this._selectedTable.rows;
var d=f.length;
for(var g=0;
g<d;
g++){var a=0;
var b=f[g].cells;
var e=b.length;
for(var c=0;
c<e;
c++){while(this._tableState[g][a]){a++;
}this._processTD(b[c],g,a);
}}},_getStateValueIndexes:function(e,c){var d={};
var a=this._tableState[e][c];
if(a){var b=a.split(",");
if(b.length==2){d.rowIndex=parseInt(b[0]);
d.colIndex=parseInt(b[1]);
}}return d;
},_getSelectedTableCellByStateIndexes:function(c,b){var a=this._getStateValueIndexes(c,b);
var d=a.rowIndex;
var c=this._selectedTable.rows[d];
return c.cells[a.colIndex];
},_getLeftTopStateIndexes:function(g,a){var e={};
var d=g+","+a;
for(var f=0;
f<this._tableStateRowsCount;
f++){var b=false;
for(var c=0;
c<this._tableStateColsCount;
c++){if(this._tableState[f][c]==d){e.rowIndex=f;
e.colIndex=c;
b=true;
break;
}}if(b){break;
}}return e;
},_getRightTopStateIndexes:function(g,a){var e={};
var d=g+","+a;
for(var f=0;
f<this._tableStateRowsCount;
f++){var b=false;
for(var c=this._tableStateColsCount-1;
c>-1;
c--){if(this._tableState[f][c]==d){e.rowIndex=f;
e.colIndex=c;
b=true;
break;
}}if(b){break;
}}return e;
},_getLeftBottomStateIndexes:function(g,a){var e={};
var d=g+","+a;
for(var f=(this._tableStateRowsCount-1);
f>-1;
f--){var b=false;
for(var c=0;
c<this._tableStateColsCount;
c++){if(this._tableState[f][c]==d){e.rowIndex=f;
e.colIndex=c;
b=true;
break;
}}if(b){break;
}}return e;
},_insertRow:function(b){var a=null;
if(this._selectedCell.tagName=="TH"){if(this._selectedRow){a=this._selectedRow.parentNode.insertRow(b);
}}else{a=this._selectedTable.insertRow(b);
}return a;
},_insertCell:function(d,a,g,h){if(!a){a=0;
}var b=null;
if(d&&d.tagName=="TR"){var c=d.parentNode;
if(c.tagName=="THEAD"){var f=d.document?d.document:d.ownerDocument;
b=f.createElement("TH");
if(g){b.innerHTML=g;
}if(d.cells.length==a){d.appendChild(b);
}else{var e=d.cells[a];
if(e){d.insertBefore(b,e);
}}}else{b=d.insertCell(a);
if(g){b.innerHTML=g;
}}$telerik.mergeElementAttributes(h,b);
this._cleanNewCellAttributes(b);
}return b;
},_cleanNewCellAttributes:function(a){if(!a){return;
}a.removeAttribute("rowSpan");
a.removeAttribute("colSpan");
a.removeAttribute("name");
a.removeAttribute("ID");
},_getRowSpan:function(b){if(b){var a=parseInt(b.getAttribute("rowSpan"));
if(isNaN(a)){a=1;
}return a;
}return 0;
},_getColSpan:function(b){if(b){var a=parseInt(b.getAttribute("colSpan"));
if(isNaN(a)){a=1;
}return a;
}return 0;
},_setRowSpan:function(b,a){if(!b){return;
}a=parseInt(a);
if(isNaN(a)||a<2){b.removeAttribute("rowSpan");
}else{b.setAttribute("rowSpan",a);
}},_setColSpan:function(b,a){if(!b){return;
}a=parseInt(a);
if(isNaN(a)||a<2){b.removeAttribute("colSpan");
}else{b.setAttribute("colSpan",a);
}},_alterRowSpan:function(c,d){var a=this._getRowSpan(c)+d;
var b=true;
if(a>0){this._setRowSpan(c,a);
}else{b=false;
}return b;
},canUndo:function(){return(0<this._currentStateIndex);
},canRedo:function(){return(this._currentStateIndex<this._states.length-1);
},undo:function(){var a=this._currentStateIndex-1;
var d=this._states[this._currentStateIndex];
if(a<this._states.length){var c=this._states[a];
if(c){this._replaceSelectedTable(c);
this._currentStateIndex--;
var b={commandName:"undo "+d.commandName,selectedColIndex:d.selectedColIndex,selectedRowIndex:d.selectedRowIndex};
this._raiseEvent("onCommand",b);
}}},redo:function(){var a=this._currentStateIndex+1;
var d=this._states[this._currentStateIndex];
if(a<this._states.length){var c=this._states[a];
if(c){this._replaceSelectedTable(c);
this._currentStateIndex++;
var b={commandName:"redo "+d.commandName,selectedColIndex:d.selectedColIndex,selectedRowIndex:d.selectedRowIndex};
this._raiseEvent("onCommand",b);
}}},_replaceSelectedTable:function(a){var b=this._selectedTable.parentNode;
var d=a.table.cloneNode(true);
b.insertBefore(d,this._selectedTable);
b.removeChild(this._selectedTable);
this.set_selectedTable(d);
var c=d.rows[a.nextSelectedRowIndex].cells[a.nextSelectedColIndex];
this._selectedCellClassName=a.selectedCellClassName;
this.set_selectedCell(c,false);
},_storeState:function(a){if(!this._selectedTable){return false;
}this._currentStateIndex++;
if(this._states.length!=0){this._states=this._states.slice(0,this._currentStateIndex);
}var b={table:this._selectedTable.cloneNode(true),selectedRowIndex:a.selectedRowIndex,selectedColIndex:a.selectedColIndex,nextSelectedRowIndex:a.nextSelectedRowIndex,nextSelectedColIndex:a.nextSelectedColIndex,selectedCellClassName:this._selectedCellClassName,commandName:a.commandName};
this._states.push(b);
},_removeEptyTrElements:function(){if(!this._selectedTable){return false;
}var d=this._selectedTable.rows;
var e=d.length;
var l=[];
var n=0;
for(var a=0;
a<e;
a++){var k=d[a];
var o=k.cells.length;
if(o==0){l[n++]=k;
if(a!=0){var f=d[a-1];
var m=f.cells;
var c=m.length;
for(var b=0;
b<c;
b++){var g=m[b];
var h=this._getRowSpan(g);
if(h>1){this._setRowSpan(g,h-1);
}}}}}for(var a=0;
a<n;
a++){var k=l[0];
k.parentNode.removeChild(k);
}},executeCommand:function(a,b){if(!this._selectedTable||!this._selectedCell||!a){return false;
}var c=true;
var d={commandName:a,selectedColIndex:this._selectedCell.cellIndex,selectedRowIndex:this._selectedRowIndex,nextSelectedColIndex:this._selectedCell.cellIndex,nextSelectedRowIndex:this._selectedRowIndex};
switch(a){case"deleteColumn":case"deleteRow":case"deleteCell":case"insertRowAbove":case"insertRowBelow":case"insertColumnToTheLeft":case"insertColumnToTheRight":case"mergeLeft":case"mergeTop":case"mergeRight":case"mergeDown":case"setAsContentCell":case"splitCellHorizontally":case"splitCellVertically":c=this[a](b);
break;
default:this._raiseException(a+" is not implemented!");
return false;
break;
}if(c){this._setTableState();
this._raiseEvent("onCommand",d);
this.set_selectedRow();
if(a!="deleteColumn"&&a!="deleteRow"&&a!="deleteCell"){d.nextSelectedColIndex=this._selectedCell.cellIndex;
d.nextSelectedColIndex=this._selectedRowIndex;
}this._storeState(d);
this._removeEptyTrElements();
}return c;
},_alterNonCurrentRowCellsRowspan:function(c,b){var a=";";
var d="";
for(var h=0;
h<this._tableStateColsCount;
h++){var e=this._getStateValueIndexes(c,h);
var g=e.rowIndex;
var f=e.colIndex;
if(e.rowIndex!=c){var d=g+","+f+";";
if(a.indexOf(";"+d)==-1){a+=d;
this._alterRowSpan(this._selectedTable.rows[g].cells[f],b);
}}}},_getNewCellIndex:function(d,c,b){var l=d+1;
var f=d+","+c;
var g=(b)?b:0;
for(var m=0;
m<this._tableStateColsCount;
m++){if(this._tableState[l][m]==f){if(m!=0){var h=m-1;
for(var a=h;
a>0;
a--){var k=this._getStateValueIndexes(l,h);
var e=k.rowIndex;
if(e==l){var m=k.colIndex;
g=parseInt(m);
break;
}}}break;
}}return g;
},deleteRow:function(h){if(!this._selectedTable){return false;
}var m=this._getLeftTopStateIndexes(this._selectedRowIndex,this._selectedCell.cellIndex);
var e=m.rowIndex;
var n=e-1;
var s=this._selectedRowIndex+1;
var b=this._selectedTable.rows[s];
if(typeof(e)!="undefined"&&typeof(m.colIndex)!="undefined"){var a=";";
var k=0;
for(var r=0;
r<this._tableStateColsCount;
r++){var l=this._tableState[e][r]+";";
if(a.indexOf(";"+l)==-1){a+=l;
var c=this._getSelectedTableCellByStateIndexes(e,r);
var g=this._getRowSpan(c);
if(g==1){}else{if(n>=0&&this._tableState[e][r]==this._tableState[n][r]){var p=this._getSelectedTableCellByStateIndexes(n,r);
this._alterRowSpan(p,-1);
}else{for(var f=r;
f>-1;
f--){var q=this._getStateValueIndexes(s,f);
if(s==q.rowIndex){k=parseInt(q.colIndex)+1;
break;
}}var o=this._insertCell(b,k,c.innerHTML,c);
this._setColSpan(o,this._getColSpan(c));
this._setRowSpan(o,g-1);
k++;
}}}}var d=this._selectedRow.parentNode;
if(d){d.removeChild(this._selectedRow);
}return true;
}},insertRowBelow:function(e){if(!this._selectedTable){return false;
}var f=this._getLeftBottomStateIndexes(this._selectedRowIndex,this._selectedCell.cellIndex);
if(typeof(f.rowIndex)!="undefined"&&typeof(f.colIndex)!="undefined"){var c=f.rowIndex;
var l=c+1;
var g=this._insertRow(l);
$telerik.mergeElementAttributes(this._selectedRow,g);
var a=";";
for(var d=0;
d<this._tableStateColsCount;
d++){stateValue=this._tableState[c][d];
if(a.indexOf(";"+stateValue+";")==-1){a+=stateValue+";";
var k=this._getSelectedTableCellByStateIndexes(c,d);
if(this._getRowSpan(k)>1&&l!=this._tableStateRowsCount&&this._tableState[c][d]==this._tableState[l][d]){this._alterRowSpan(k,1);
}else{var h=this._insertCell(g,g.cells.length,"&nbsp;",k);
var b=this._getColSpan(k);
if(b>1){this._setColSpan(h,b);
}}}}}return true;
},insertRowAbove:function(f){if(!this._selectedTable){return false;
}var g=this._insertRow(this._selectedRowIndex);
$telerik.mergeElementAttributes(this._selectedRow,g);
var c=0;
var e=this._selectedRowCells.length;
this._alterNonCurrentRowCellsRowspan(this._selectedRowIndex,1);
for(var a=0;
a<e;
a++){var d=this._selectedRowCells[a];
var b=this._getColSpan(this._selectedRowCells[a]);
var h=this._insertCell(g,c++,"&nbsp;",d);
if(b>1){this._setColSpan(h,b);
}}return true;
},insertColumnToTheLeft:function(o){if(!this._selectedTable){return false;
}var m=this._getLeftTopStateIndexes(this._selectedRowIndex,this._selectedCell.cellIndex);
if(typeof(m.colIndex)!="undefined"){var p=parseInt(m.colIndex);
if(isNaN(p)){p=0;
}for(var l=0;
l<this._tableStateRowsCount;
l++){var q=this._selectedTable.rows[l];
var n=this._getStateValueIndexes(l,p);
var b=n.rowIndex;
var h=n.colIndex;
if(b==l){var d=false;
if(p==0){d=true;
}else{var g=this._selectedTable.rows[b].cells[h];
var f=this._getColSpan(g);
if(this._tableState[l][p]==this._tableState[l][p-1]&&f>1&&l!=this._selectedRowIndex){g.setAttribute("colSpan",f+1);
var k=this._getRowSpan(g);
if(k>1){for(var a=1;
a<k;
a++){l++;
}}}else{d=true;
}}if(d){var c=this._insertCell(q,h,"&nbsp;",q.cells[h]);
}}else{var e=0;
for(var a=p-1;
a>-1;
a--){var n=this._getStateValueIndexes(l,a);
if(n.rowIndex==l){e=n.colIndex+1;
break;
}}var g=this._getSelectedTableCellByStateIndexes(l,p);
var c=this._insertCell(q,e,"&nbsp;",g);
}}}return true;
},insertColumnToTheRight:function(o){if(!this._selectedTable){return false;
}var m=this._getRightTopStateIndexes(this._selectedRowIndex,this._selectedCell.cellIndex);
if(typeof(m.colIndex)!="undefined"){var p=parseInt(m.colIndex);
if(isNaN(p)){p=0;
}for(var l=0;
l<this._tableStateRowsCount;
l++){var q=this._selectedTable.rows[l];
var n=this._getStateValueIndexes(l,p);
var b=n.rowIndex;
var h=parseInt(n.colIndex);
if(isNaN(h)){h=0;
}if(b==l){var d=false;
if(p==this._tableStateColsCount-1){d=true;
}else{var g=this._selectedTable.rows[b].cells[h];
var f=this._getColSpan(g);
if(this._tableState[l][p]==this._tableState[l][p+1]&&f>1&&l!=this._selectedRowIndex){g.setAttribute("colSpan",f+1);
var k=this._getRowSpan(g);
if(k>1){for(var a=1;
a<k;
a++){l++;
}}}else{d=true;
}}if(d){var c=this._insertCell(q,h+1,"&nbsp;",q.cells[h]);
}}else{var e=this._selectedTable.rows[l].cells.length;
for(var a=p+1;
a<this._tableStateColsCount;
a++){var n=this._getStateValueIndexes(l,a);
if(n.rowIndex==l){e=parseInt(n.colIndex);
if(isNaN(e)){e=0;
}break;
}}var g=this._getSelectedTableCellByStateIndexes(l,p);
var c=this._insertCell(q,e,"&nbsp;",g);
}}}return true;
},deleteColumn:function(k){if(!this._selectedTable){return false;
}var g=this._getLeftTopStateIndexes(this._selectedRowIndex,this._selectedCell.cellIndex);
var l=g.colIndex;
if(typeof(l)!="undefined"){for(var f=0;
f<this._tableStateRowsCount;
f++){var m=this._selectedTable.rows[f];
var h=this._getStateValueIndexes(f,l);
var e=parseInt(h.colIndex);
var d=m.cells[e];
var c=this._getRowSpan(d);
var b=this._getColSpan(d);
if(b>1){this._setColSpan(d,b-1);
}else{m.removeChild(d);
}if(c>1){for(var a=1;
a<c;
a++){f++;
}}}return true;
}return false;
},canMergeLeft:function(e){if(!e){e=this._selectedCell;
}if(!e||!e.parentNode){return false;
}var d=true;
var b=e.cellIndex;
var c=e.parentNode;
var g=c.rowIndex;
if(b==0||b==-1){d=false;
}else{var f=this._getLeftTopStateIndexes(g,b);
if(typeof(f.rowIndex)=="undefined"||typeof(f.colIndex)=="undefined"){return false;
}var h=this._getSelectedTableCellByStateIndexes(f.rowIndex,f.colIndex-1);
if(h){var k=h.parentNode.rowIndex;
var a=this._getRowSpan(h);
if(k!=g||this._getRowSpan(e)!=this._getRowSpan(h)){d=false;
}}}return d;
},mergeLeft:function(a){var f=(a&&a.cell)?a.cell:this._selectedCell;
if(!f||!f.parentNode){return false;
}var c=true;
var e=f.parentNode;
if(this.canMergeLeft(f)){var d=e.cells[f.cellIndex-1];
this._setColSpan(f,this._getColSpan(f)+this._getColSpan(d));
var b=d.innerHTML;
if(b!=" "&&b!="&nbsp;"){f.innerHTML=b+"<br />"+f.innerHTML;
}e.removeChild(d);
}else{this._raiseException("The cell can not be merged left!");
c=false;
}return c;
},canMergeTop:function(e){if(!e){e=this._selectedCell;
}if(!e||!e.parentNode){return false;
}var d=true;
var a=e.parentNode.rowIndex;
if(a==0){d=false;
}else{var b=this._getLeftTopStateIndexes(a,e.cellIndex);
if(typeof(b.rowIndex)=="undefined"||typeof(b.colIndex)=="undefined"){return false;
}var c=this._getSelectedTableCellByStateIndexes(b.rowIndex-1,b.colIndex);
d=this.canMergeDown(c);
}return d;
},mergeTop:function(a){var g=(a&&a.cell)?a.cell:this._selectedCell;
if(!g||!g.parentNode){return false;
}var e=true;
if(this.canMergeTop(g)){var f=g.parentNode;
var b=this._getLeftTopStateIndexes(f.rowIndex,g.cellIndex);
var c=this._getSelectedTableCellByStateIndexes(b.rowIndex-1,b.colIndex);
var d=g.innerHTML;
if(d!=" "&&d!="&nbsp;"){c.innerHTML+="<br />"+d;
}this.set_selectedCell(c,false);
this._alterRowSpan(c,this._getRowSpan(g));
f.removeChild(g);
}else{this._raiseException("The cell cannot be merged top!");
e=false;
}return e;
},canMergeRight:function(e){if(!e){e=this._selectedCell;
}if(!e||!e.parentNode){return false;
}var d=true;
var a=e.cellIndex;
var f=e.parentNode;
var c=f.rowIndex;
if(typeof(c)=="undefined"){return false;
}var h=f.cells.length;
if(a==h-1){d=false;
}else{var g=this._getRightTopStateIndexes(c,a);
if(typeof(g.rowIndex)=="undefined"||typeof(g.colIndex)=="undefined"){return false;
}var b=this._getSelectedTableCellByStateIndexes(g.rowIndex,g.colIndex+1);
if(b&&(b.parentNode.rowIndex!=c||this._getRowSpan(e)!=this._getRowSpan(b))){d=false;
}}return d;
},mergeRight:function(a){var f=(a&&a.cell)?a.cell:this._selectedCell;
if(!f||!f.parentNode){return false;
}var c=true;
if(this.canMergeRight(f)){var e=f.parentNode;
var b=e.cells[f.cellIndex+1];
var d=b.innerHTML;
if(d!=" "&&d!="&nbsp;"){f.innerHTML+="<br />"+d;
}this._setColSpan(f,this._getColSpan(f)+this._getColSpan(b));
e.removeChild(b);
}else{this._raiseException("The cell can not be merged right!");
c=false;
}return c;
},canMergeDown:function(f){if(!f){f=this._selectedCell;
}if(!f||!f.parentNode){return false;
}var e=true;
var d=this._getRowSpan(f);
var c=this._getColSpan(f);
var n=f.parentNode.rowIndex;
var b=n+d;
if(b==this._tableStateRowsCount){e=false;
}else{var l=this._getLeftTopStateIndexes(n,f.cellIndex);
if(typeof(l.colIndex)!="undefined"){var o=l.colIndex;
var m=this._getStateValueIndexes(b,o);
var k=m.rowIndex;
var g=parseInt(m.colIndex);
var h=this._selectedTable.rows[k].cells[g];
if(h.parentNode.parentNode.tagName!=f.parentNode.parentNode.tagName){return false;
}var a=this._getColSpan(h);
if(c!=a){e=false;
}else{if(o!=0){if(this._tableState[b][o-1]==this._tableState[b][o]){e=false;
}}}}}return e;
},mergeDown:function(b){var f=(b&&b.cell)?b.cell:this._selectedCell;
if(!f||!f.parentNode){return false;
}var d=true;
if(this.canMergeDown(f)){var c=this._getLeftBottomStateIndexes(f.parentNode.rowIndex,f.cellIndex);
var a=this._getSelectedTableCellByStateIndexes(c.rowIndex+1,c.colIndex);
var e=a.innerHTML;
if(e!=" "&&e!="&nbsp;"){f.innerHTML+="<br />"+e;
}this._alterRowSpan(f,this._getRowSpan(a));
a.parentNode.removeChild(a);
}else{this._raiseException("The cell can not be merged down!");
d=false;
}return d;
},canDeleteCell:function(f){if(!f){f=this._selectedCell;
}if(!f||!f.parentNode){return false;
}var h=0;
var g=this._getRowSpan(f);
var e=this._getColSpan(f);
var b=f.parentNode.rowIndex;
var a=f.cellIndex;
var d=this._getLeftTopStateIndexes(b,a);
var c=this._getLeftBottomStateIndexes(b,a);
if(g==this._tableStateRowsCount){h=1;
}else{if(e==this._tableStateColsCount){h=2;
}else{if(this.canMergeLeft(f)){h=3;
}else{if(this.canMergeRight(f)){h=4;
}else{if(this.canMergeDown(f)){h=5;
}else{if(this.canMergeTop(f)){h=6;
}}}}}}return h;
},deleteCell:function(h){var d=(h&&h.cell)?h.cell:this._selectedCell;
if(!d||!d.parentNode){return false;
}var c=true;
var g=d.parentNode;
var k=this.canDeleteCell(d);
switch(k){case 1:g.removeChild(d);
break;
case 2:g.parentNode.removeChild(g);
break;
case 3:var l=g.cells[d.cellIndex-1];
this.set_selectedCell(l,false);
c=this.mergeRight();
break;
case 4:var a=g.cells[d.cellIndex+1];
this.set_selectedCell(a,false);
c=this.mergeLeft();
break;
case 5:var e=this._getLeftBottomStateIndexes(g.rowIndex,d.cellIndex);
var b=this._getSelectedTableCellByStateIndexes(e.rowIndex+1,e.colIndex);
this.set_selectedCell(b,false);
c=this.mergeTop();
break;
case 6:var e=this._getLeftBottomStateIndexes(g.rowIndex,d.cellIndex);
var f=this._getSelectedTableCellByStateIndexes(e.rowIndex-1,e.colIndex);
this.set_selectedCell(f,false);
c=this.mergeDown();
break;
default:this._raiseException("The cell can not be deleted!");
c=false;
break;
}if(c&&g&&g.cells.length==0){g.parentNode.removeChild(g);
}return c;
},splitCellHorizontally:function(l){if(!this._selectedCell){return false;
}var c=this._selectedCell;
var q=true;
var d=this._getColSpan(c);
var o=c.cellIndex;
var r=this._selectedRow;
var a=this._selectedRowIndex;
var b=a+","+o;
var p=this._insertCell(r,o+1,"&nbsp;",c);
this._setRowSpan(p,this._getRowSpan(c));
if(d==1){var g=this._getLeftTopStateIndexes(a,o);
var u=g.colIndex;
var n=";";
for(var e=0;
e<this._tableStateRowsCount;
e++){var k=this._tableState[e][u];
if(e!=a&&k!=b&&n.indexOf(";"+k+";")){n+=k+";";
var t=this._getSelectedTableCellByStateIndexes(e,u);
this._setColSpan(t,this._getColSpan(t)+1);
}}}else{var f=(l)?parseInt(l.rightColSpan):null;
if(!f||isNaN(f)||f>=d){var h=Math.ceil(d/2);
var m,s;
if(d%2==0){m=h;
s=h;
}else{m=h;
s=h-1;
}}else{m=d-f;
s=f;
}this._setColSpan(c,m);
this._setColSpan(p,s);
}return q;
},splitCellVertically:function(h){var b=this._selectedCell;
if(!b){return false;
}if(!b.parentNode){return false;
}var n=true;
var s=this._getRowSpan(b);
var d=b.cellIndex;
var o=this._selectedRow;
var p=this._selectedRowIndex;
var g=this._selectedRowCells;
var a=g.length;
var k=";";
var q=null;
var f=[];
if(s==1){for(var r=0;
r<this._tableStateColsCount;
r++){q=this._getSelectedTableCellByStateIndexes(p,r);
stateValue=this._tableState[p][r];
f=this._getStateValueIndexes(p,r);
if((q.cellIndex!=d||p!=f.rowIndex)&&k.indexOf(";"+stateValue+";")==-1){k+=stateValue+";";
this._alterRowSpan(q,1);
}}newRow=this._insertRow(p+1);
$telerik.mergeElementAttributes(o,newRow);
newCell=this._insertCell(newRow,newRow.cells.length,"&nbsp;",b);
this._setColSpan(newCell,this._getColSpan(b));
}else{var e=Math.ceil(s/2),c,m;
var l=(h)?parseInt(h.downRowSpan):null;
if(!l||isNaN(l)||l>=s){if(s%2==0){c=e;
m=e;
}else{c=e;
m=e-1;
}}else{c=s-l;
m=l;
}this._setRowSpan(b,c);
arStateIndexes=this._getLeftTopStateIndexes(p,d);
alterRowIndex=p+c;
newCellColIndex=0;
for(var r=arStateIndexes.colIndex;
r>-1;
r--){f=this._getStateValueIndexes(alterRowIndex,r);
if(f.rowIndex==alterRowIndex){newCellColIndex=f.colIndex+1;
break;
}}newCell=this._insertCell(this._selectedTable.rows[alterRowIndex],newCellColIndex,"&nbsp;",b);
this._setColSpan(newCell,this._getColSpan(b));
this._setRowSpan(newCell,m);
}return n;
},setAsContentCell:function(a){var b=this._selectedCell;
if(!b){return false;
}if(!b.parentNode){return false;
}b.style.width="100%";
b.style.height="100%";
return true;
},add_onCommand:function(a){this.get_events().addHandler("onCommand",a);
},_raiseEvent:function(b,c){var a=this.get_events().getHandler(b);
if(a){if(!c){c=Sys.EventArgs.Empty;
}a(this,c);
}}};
Telerik.Web.UI.LayoutBuilderEngine.registerClass("Telerik.Web.UI.LayoutBuilderEngine",Telerik.Web.UI.RadWebControl);
